import { director, find, Game, game, Label, Node, Vec3, _decorator } from 'cc';
import { EventMgr } from '../../../Framework/Scripts/Managers/EventMgr';
import { UIComponent, UIMgr } from '../../../Framework/Scripts/Managers/UIMgr';
import { constant } from '../constant';

const { ccclass, property } = _decorator;


/** 
  周无邪出品
  本源码用于学习研究使用。
  作者联系方式：tuya7078（微信）。
 */
@ccclass
export default class showTip_UICtrl extends UIComponent {

    private title: Label = null

    private tipUI: Node = null
    private showBtnUI: Node = null
    private btnLabel: Label = null

    onLoad() {
       

        this.title = this.ViewNode ("title").getComponent(Label)
        this.tipUI = this.ViewNode("tipUI")
        this.showBtnUI = this.ViewNode("showBtnUI")
        this.btnLabel = this.ViewNode("showBtnUI/Btn/Label").getComponent(Label)

        EventMgr.Instance.AddEventListener(constant.EVENT_NAME.showTip,  this.upLabel,this)
    }
    onDestroy() {
        //  console.log("关闭了窗口");
        EventMgr.Instance.RemoveEventListener(constant.EVENT_NAME.showTip,  this.upLabel,this)

        //   director.resume()
    }

    private upLabel(name: string, updata) {
        // const upData = {
        //     title: str,
        //     fun: fun,
        //     btnStr: btnStr,
        //     isAD:isAD
        // }
        if (updata["fun"]) {



            //director.pause()

            this.tipUI.active = false
            this.showBtnUI.active = true
            if (!updata["isAD"]) {
                //有广告显示指定文字
                this.ViewNode("showBtnUI/Btn/icon").active = false
              
                this.btnLabel.node.position = new Vec3(0, 0, 0)
             //   this.btnLabel.fontSize = 30
            } else {
                //文字显示“确定”
                this.ViewNode("showBtnUI/Btn/icon").active = true
                this.btnLabel.node.position = new Vec3(18, 0, 0)
               // this.btnLabel.fontSize = 20
            }
            this.title.string = updata["title"]
            this.title.node.position = new Vec3(0, 30, 0)
            this.btnLabel.string = updata["btnStr"]
            this.AddButtonListener("showBtnUI/x1", this, () => {
             //   console.log("点击了关闭");
                director.resume()
                UIMgr.Instance.DestroyUIView(this.node.name)
            })

            this.AddButtonListener("showBtnUI/Btn", this, () => {
               // console.log("点击按钮");

                updata["fun"]()
                UIMgr.Instance.DestroyUIView(this.node.name)
            })


        } else {
            this.AddButtonListener("mask_bg", this, () => {
                UIMgr.Instance.DestroyUIView(this.node.name)

            })
            this.tipUI.active = true
            this.showBtnUI.active = false
            this.ViewNode("Label").active = false
            this.title.node.position = new Vec3(0, 0, 0)
            this.title.string = updata["title"]
            this.scheduleOnce(() => {
                UIMgr.Instance.DestroyUIView(this.node.name)
            }, 2)
        }

    }



    start() {

    }

    // update (dt) {}
}
